package com.e3.basdoc.tax.server;

import java.util.ArrayList;
import java.util.List;

import com.e3.basdoc.tax.client.TaxRPCService;
import com.e3.basdoc.tax.model.TaxModel;
import com.e3.basdoc.tax.model.TaxQC;
import com.e3.core.base.ServiceException;
import com.e3.web.core.client.WebException;
import com.e3.web.core.server.GwtRPCAction;
import com.e3.web.core.server.GwtRPCExecutor;
import com.e3.web.core.server.GwtRPCVoidExecutor;

public class TaxRPCServiceImpl extends GwtRPCAction implements	TaxRPCService {
	
	public TaxModel newTax(final TaxModel model) throws WebException {
		return new GwtRPCExecutor<TaxModel>() {
			@Override
			public TaxModel execute() throws ServiceException, Exception {
				return TaxServiceClient.getTaxService().newTax(model);
			}
		}.doExecute();
	}

	public TaxModel modifyTax(final TaxModel model) throws WebException {
		return new GwtRPCExecutor<TaxModel>() {
			@Override
			public TaxModel execute() throws ServiceException, Exception {
				return TaxServiceClient.getTaxService().modifyTax(model);
			}
		}.doExecute();
	}

	public List<TaxModel> getTaxByCondition(final TaxQC taxQC) throws WebException {
		return new GwtRPCExecutor<List<TaxModel>>() {
			@Override
			public List<TaxModel> execute() throws ServiceException, Exception {
				return TaxServiceClient.getTaxQueryService().getTaxByCondition(taxQC);
			}
		}.doExecute();
	}

	public void deleteTaxs(List<TaxModel> models) throws WebException {
		if(models == null||models.isEmpty()){
			return;
		}
		final List<Long> ids = new ArrayList<Long>(models.size());
		for (TaxModel taxModel : models) {
			ids.add(taxModel.getId());
		}
		
		new GwtRPCVoidExecutor() {
			@Override
			public void execute() throws ServiceException, Exception {
				TaxServiceClient.getTaxService().deleteTaxByIds(ids);
			}
		}.doExecute();
	}

}
